package com.easyaop.test.core.pointcut;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;

/**
 * @author lipan
 * @since 2025-01-25
 */
public class MethodPointcutWrapper {
    private MethodPointcut pointcut;

    public MethodPointcutWrapper(MethodPointcut pointcut) {
        this.pointcut = pointcut;
    }

    public static MethodPointcutWrapper wrapper(MethodPointcut pointcut) {
        return new MethodPointcutWrapper(pointcut);
    }

    public ElementMatcher<? extends TypeDescription> getClassNameMatcher() {
        return ElementMatchers.named(pointcut.getClassName());
    }

    public ElementMatcher<? super MethodDescription> getMethodMatcher() {
        return ElementMatchers.isMethod().and(ElementMatchers.named(pointcut.getClassName())).and(ElementMatchers.hasDescriptor(pointcut.getMethodDescriptor()));
    }
}
